import {toast} from '@/utils/common'

let timeout = 5000;

const nRequest = config => {
    config.header = config.header || {}
    // get请求映射params参数
    return new Promise((resolve, reject) => {
        uni.request({
            method: config.method,
            timeout: timeout,
            url: config.url,
            data: config.data,
            header: config.header,
            dataType: 'json'
        }).then(response => {
            let [error, res] = response
            if (error) {
                toast(error)
                reject(error)
                return
            }
            resolve(res.data)
        }).catch(error => {
            toast(message)
            reject(error)
        })
    })
}

export default nRequest
